<template>
  <div>
    <van-nav-bar left-arrow @click-left="onClickLeft">
      <template #left>
        <van-icon name="arrow-left" color="#000" size="24" />
      </template>
    </van-nav-bar>
    <!-- 标题 -->
    <div class="ticktitle" style="margin-top:100px;margin-left:30px;margin-bottom:200px">
      <div>
        <van-button  type="warning">票</van-button>
      </div>
      <div>
        <span style="margin-left:10px;">手机号码登录</span>
      </div>

    </div>
    <!-- fromdata -->
    <!-- 这个字体大小怎么改不了 -->
    <van-form @submit="onSubmit" :show-error="false">
    <div style="margin-left:20px;width:340px">
      <div>
        <van-field v-model="tel" border 
        left-icon="https://b.yzcdn.cn/vant/icon-demo-1126.png" type="tel" label="+86"
          line-height placeholder="请输入手机号"
          :rules="[
            {required:true,message:'请输入手机号'},
            {
              validator:validatetel,
              message:'手机号码必须为11位'
            }
          ]"
          >
        </van-field>
      </div>
      <div>
        <!-- left-icon="idcard" -->
        <van-field v-model="str" border type="str" placeholder="请输入验证码"
        :rules="[
            {required:true,message:'请输入验证码'},
            ]">
          <template #left-icon>
            <xicon />
          </template>
          <template #button>
            <van-button disabled size="small" color="#000">获取验证码</van-button>
          </template>
        </van-field>
        <div style="margin-left:130px;margin-top:20px">
      <van-button :disabled="disabled"  type="warning"  @click="clickHandler">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;登录&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</van-button>
    </div>
      </div>
    </div>

    <!-- 登录按钮 -->
    
    <div style="margin-left:100px;margin-top:15px">
      <span style="font-size: 9px;color:silver">未注册的用户将自动创建新账号</span>
    </div>
    <div style="margin-left:140px;margin-top:40px">
      <span style="font-size: 10px;color:grey">或通过一下方式登录</span>
    </div>
    <div class="icons" style="margin-left:35px;margin-top:20px">
      <div>
        <xicon  icon='icon-zhifubao'/>
      </div>
      <div>
        <xicon icon='icon-taobao'/>
      </div>
      <div>
        <xicon icon='icon-weibo'/>
      </div>
      <div>
        <xicon icon='icon-QQ'/>
      </div>
      <div>
        <xicon icon='icon-weixin'/>
      </div>

    </div>
  </van-form>
  </div>
</template>

<script>

export default {
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    clickHandler(){
      this.$router.replace({path:'/homepage'})
    },
    validatetel(value){

      return value.length==11
    },
    async onSubmit(userData){
      this.disabled=true
      let code= await this.$store.dispatch('user/loginAction',userData)
      if(code==0){
        this.disabled = false
        let url=this.$store.state.redirectUrl
        this.$router.replace(url)
      }else{
        this.$toast({
          type:'none',
          duration:3000,
          message:'账号或密码不正确',
          onClose: () => (this.disabled = false)
        })
      }
    }
  },
  data() {
    return {
      disabled:false,
      tel: '15165433687',
      str: '2h5m',
    };
  },
}
</script>

<style lang="scss" scoped>
.ticktitle {
  div {
    float: left;

  }
}
.icons{
  div{
    float:left;
    margin-left: 13px;
  }
}
</style>
